home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 October: Mac OS SDK / Dev.CD Oct 97 SDK1.toast / Development Kits (Disc 1) / QuickDraw GX / Programming Stuff / Sample Code / Printing Samples / About the QuickDraw PICT shape next >
Encoding:
Text File  |  1995-04-10  |  10.3 KB  |  160 lines  |  [ttro/ttxt]

  1. A commonly asked question:
  2.  
  3. "In pre beta-4 GX, the page passed to gxRenderPage could be easily dis-assembled into its component parts with GXGetPictureParts.  Since Beta-4 only jobs spooled from a new-API application can be analyzed. From old-API apps, the picture only contains one part, usually a rectangle."
  4.  
  5. At about beta 4, there was a new type of gxShape introduced, the "QuickDraw shape."  This shape is explained in the GX Printing book (page 4-18) and in the GX Extensions and Drivers book (page 3-6).  The text from those references appears at the end of this message.  When you print from an old app, these shapes are created by default.  They are essentially the old PICT data in a GX shape wrapper.  Two of the reasons thay we do things this way is that it decreases spooling time, and since the PICT is converted as needed at rendering time, it's easier on the imaging engine memory-wise.
  6.  
  7. You can convert the shape into a gxPicture shape by calling:
  8.  
  9.              GXSetShapeType(aQDShape, gxPictureType);
  10.  
  11. You can also disable the QD shape generation at spool time by overriding GXFetchTaggedData and looking for a 'pcfg' resource being loaded.  If you clear the high bit of the data being returned, the application's data will be written into the spool file without using the QuickDraw shape.  However, this approach is not recommended, since we added the QD shape for very good reasons, and even if you turn it off during spooling, you'll still need to deal with the case of a redirected file containing QD shapes.
  12.  
  13.  
  14.          When will QuickDraw GX translate the “QuickDraw shape”??
  15.  
  16. QuickDraw GX will do the conversions from the QuickDraw data to QDGX shapes in the default implementations of gxPostScriptProcessShape for PostScript drivers, and gxImagePage for vector and raster drivers.
  17.  
  18. So, if your printer driver or printing extension needs to convert the shape, doing so in gxDespoolPage or gxRenderPage would make sense.  (gxRenderPage sends gxImagePage, and for PostScript drivers gxRenderPage sends gxPostScriptProcessShape.)
  19.  
  20. If simply parsing the “QuickDraw shape” will give you enough information, then you should not convert the shape to a gxPicture.  Rather, use the code on this CD entitled TranslateQDShape.c to parse the shape, and leave the original intact.
  21.  
  22.  
  23.             Inside Macintosh information about “QuickDraw shapes.”
  24.  
  25. [Inside Macintosh QuickDraw GX Printing, page 3-5]
  26.  
  27. Spooling Translated QuickDraw Data in Print Files
  28.  
  29. When spooling a file that contains QuickDraw drawing commands, QuickDraw GX by default stores untranslated QuickDraw data in the print file. When the print file is despooled and imaged, QuickDraw GX then converts the data to QuickDraw GX shapes and prints them. If you want to force QuickDraw GX to translate QuickDraw data to QuickDraw GX shapes before spooling, you can override the GXFetchTaggedData message that QuickDraw GX sends at spooling time to fetch resource data of type 'pcfg'. Your override should forward the message, and then clear the highest-order bit of the data that is returned from the message. If the data’s highest-order bit is cleared, QuickDraw GX translates and stores the data in the print file as QuickDraw GX shapes. For more information on QuickDraw data in print files, see the discussion of the 'pict' tag object in the advanced printing features chapter of Inside Macintosh: QuickDraw GX Printing.
  30.  
  31.  
  32. [Inside Macintosh QuickDraw GX Printing, page 3-6]
  33.  
  34. Despooling Print Files Containing QuickDraw Picture Data
  35.  
  36. When a document containing QuickDraw imaging commands is spooled, QuickDraw GX by default saves the QuickDraw data for each page in a tag object of tag type 'pict' attached to a rectangle shape. If you examine the contents of a despooled file, note that the presence of a rectangle shape with such an attached tag object indicates the presence of QuickDraw picture data. For more information, see the discussion of the 'pict' tag object in the advanced printing features chapter of Inside Macintosh: QuickDraw GX Printing.
  37.  
  38.  
  39. [Inside Macintosh QuickDraw GX Printing, page 4-18]
  40.  
  41. QuickDraw Picture Synonym
  42.  
  43. When QuickDraw GX spools a document containing QuickDraw imaging commands, it creates and flattens, for each page, a QuickDraw GX rectangle shape with an attached tag object of tag type 'pict' (the QuickDraw GX constant for that tag type is gxQuickDrawPictTag). The tag object contains information that specifies the characteristics and location of a file containing QuickDraw picture data for that page.
  44.  
  45. When QuickDraw GX subsequently despools the file, it (or the printer driver) uses the QuickDraw GX Translator to convert the QuickDraw picture data into a QuickDraw GX picture shape before printing it. The tag object contains a gxQuickDrawPict structure:
  46.  
  47.          struct gxQuickDrawPict {
  48.             gxTranslationOptions            options;
  49.             Rect                            srcRect;
  50.             Point                           styleStretch;
  51.             unsigned long                   dataLength;
  52.             struct gxBitmapDataSourceAlias  alias;
  53.          };
  54.  
  55. Field descriptions
  56.  
  57. options - The translation options to be used by the QuickDraw GX Translator when converting the QuickDraw data.
  58.  
  59. srcRect - The source rectangle for the translation, in QuickDraw coordinates. It controls scaling of the image. This rectangle is the QuickDraw picture frame that bounds the QuickDraw data.
  60.  
  61. styleStretch - The scale factor (both horizontal and vertical) to apply to certain items, such as dashes, in QuickDraw picture comments.
  62.  
  63. dataLength - The length of the QuickDraw picture data, in bytes.
  64.  
  65. alias - A structure that defines the location of the file containing the QuickDraw data, and the offset within the file to that data.
  66.  
  67. The QuickDraw GX rectangle shape that the tag object is attached to specifies the destination bounding rectangle for drawing the QuickDraw data (in QuickDraw coordinates). The relative sizes of the source rectangle and destination rectangle control the scaling of the image when it is translated.
  68.  
  69. The QuickDraw GX Translator is described in the environment chapter of Inside Macintosh: QuickDraw GX Environment and Utilities. Tag objects are described in the tag objects chapter of Inside Macintosh: QuickDraw GX Objects. The gxBitmapDataSourceAlias structure is described in the bitmap shapes chapter of Inside Macintosh: QuickDraw GX Graphics.
  70.  
  71.  
  72. [Inside Macintosh QuickDraw GX Graphics, page 5-65]
  73.  
  74. Bitmap Data Source Alias Structure
  75.  
  76. QuickDraw GX provides the bitmap data source alias structure to allow you to specify file information for disk-based pixel images.
  77.  
  78.          struct gxBitmapDataSourceAlias {
  79.             unsigned long    fileOffset;
  80.             unsigned long    aliasRecordSize;
  81.             unsigned char    aliasRecord[gxAnyNumber];
  82.          };
  83.  
  84. Field descriptions
  85. fileOffset - The offset in bytes from the beginning of the file to the first pixel value of the pixel image.
  86.  
  87. aliasRecordSize - The size in bytes of the alias record.
  88.  
  89. aliasRecord - A Macintosh Alias Manager alias record specifying the file containing the pixel image.
  90.  
  91. For an example of a bitmap with a disk-based pixel image, see “Creating Bitmaps With Disk-Based Pixel Images” beginning on page 5-44.
  92.  
  93.  
  94. [Inside Macintosh QuickDraw GX Graphics, page 5-44]
  95.  
  96. Creating Bitmaps With Disk-Based Pixel Images
  97.  
  98. QuickDraw GX allows you to store the pixel image of a bitmap shapes in a disk file. To create this type of bitmap, you specify a predefined constant for the image field of the bitmap’s geometry:
  99.  
  100.       aBitmapGeometry.image = gxBitmapFileAliasImageValue;
  101.  
  102. The other fields of the geometry you can initialize as you would for other bitmaps:
  103.  
  104.      aBitmapGeometry.width = widthOfDiskBasedImage;
  105.    aBitmapGeometry.height = heightOfDiskBasedImage;
  106.      aBitmapGeometry.rowBytes = rowBytesOfDiskBasedImage;
  107.      aBitmapGeometry.pixelSize = pixelSizeOfDiskBasedImage;
  108.  
  109.      aBitmapGeometry.space = colorSpaceOfDiskBasedImage;
  110.      aBitmapGeometry.set = colorSetOfDiskBasedImage;
  111.      aBitmapGeometry.profile = colorProfileOfDiskBasedImage;
  112.  
  113. You still create the bitmap using the GXNewBitmap function:
  114.  
  115.     aBitmapShape = GXNewBitmap(&aBitmapGeometry, &initialLocation);
  116.  
  117. You specify the file that contains the pixel image using the bitmap data source alias structure, which is defined by the gxBitmapDataSourceAlias data type:
  118.  
  119. struct gxBitmapDataSourceAlias {
  120.    unsigned long    fileOffset;              /* offset (in bytes) to image */
  121.    unsigned long    aliasRecordSize;         /* size of alias record */
  122.    unsigned char    aliasRecord[gxAnyNumber];/* alias record */
  123. };
  124.  
  125. To use this data type, you need to declare a variable to hold the structure:
  126.  
  127. gxBitmapDataSourceAlias anAlias;
  128.  
  129. Then, you need to set the three fields of the structure:
  130.  
  131. • the aliasRecord field should contain a Macintosh Alias Manager alias record specifying the file containing the pixel image
  132.  
  133. • the aliasRecordSize field should specify the size in bytes of the alias record
  134.  
  135. • the fileOffset field should specify the offset in bytes from the beginning of the data fork of the file to the first pixel value of the pixel image
  136.  
  137. Once you’ve created the bitmap data source alias structure, you create a tag object to encapsulate the structure, using the call
  138.  
  139. anAliasTag = GXNewTag(gxBitmapFileAliasTagType, sizeOf(anAlias) &anAlias);
  140.  
  141. Then you associate the tag object with the bitmap shape using the call
  142.  
  143. GXSetShapeTags(aBitmapShape, gxBitmapFileAliasTagType,
  144.                1,                    /* first tag */
  145.               –1,                    /* replace all tags of same type */
  146.                1,                    /* insert one new tag */
  147.                &anAliasTag);         /* tag to insert */
  148.  
  149. Now the disk-based bitmap is completely initialized. You can use most bitmap-related functions with this bitmap, but there are bitmap-related functions you cannot use. In particular, you cannot call the GXSetBitmapParts, GXSetShapePixel, GXNewViewDevice, or GXSetViewDeviceBitmap functions, as these functions would require QuickDraw GX to write to the file.
  150.  
  151. For more information about alias records, see the chapter “Alias Manager” of Inside Macintosh: Files.
  152.  
  153. For more information about tags and the GXNewTag function, see the chapter “Tag Objects” of Inside Macintosh: QuickDraw GX Objects. For information about the GXSetShapeTags function, see the chapter “Shape Objects” in that book.
  154.  
  155. "phew!"
  156.  
  157. - Dave Hersey 8/30/94
  158.  
  159.  
  160.